import taichi as ti

ti.init()

@ti.kernel
def sum():
    for i in x:
        # ok
        total[None]+=x[i]
        # ok
        ti.atomic_add(total[None],x[i])
        # wrong result
        total[None]=total[None]+x[i]

total = ti.field(dtype=ti.f32,shape=())
x = ti.field(dtype=ti.f32,shape=10)
print(x)
sum()
print(total)